/*«Copyright 2006, 2007 Yann Arthur Nicolas»
 *www.merlinsource.com
 *yannart@gmail.com
 *
 * This file is part of SquaresImg.
 *
 * SquaresImg is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * SquaresImg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package gui;

import chooser.ImageFileSave;
import java.awt.image.BufferedImage;

/**
 *
 * @author  Yann Arthur Nicolas
 */
public class DialogImagenFinal extends javax.swing.JDialog {
    
    private BufferedImage bi;
    private ImageFileSave filesave;
    
    public DialogImagenFinal(MainFrame parent, boolean modal, BufferedImage bi) {
        super(parent, modal);
        initComponents();
        this.bi = bi;
        imagepanel = new ImagePanel(jScrollPane1);
        jScrollPane1.setViewportView(imagepanel);
        filesave = new ImageFileSave(bi);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanelImgPrincipal = new javax.swing.JPanel();
        jButtonGuardar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jButtonZoomIn = new javax.swing.JButton();
        jButtonZoomOut = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabelPorcent = new javax.swing.JLabel();
        jButtonZoom100 = new javax.swing.JButton();
        jButtonZoomAjuste = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(java.util.ResourceBundle.getBundle("lang").getString("image_generated"));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Diskette.png")));
        jButtonGuardar.setText(java.util.ResourceBundle.getBundle("lang").getString("image_save"));
        jButtonGuardar.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("image_save_on_disk"));
        jButtonGuardar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonGuardarMouseClicked(evt);
            }
        });

        jScrollPane1.setBackground(new java.awt.Color(204, 204, 255));
        jScrollPane1.setAutoscrolls(true);

        jButtonZoomIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/zoomin.png")));
        jButtonZoomIn.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("zoom_in"));
        jButtonZoomIn.setBorder(null);
        jButtonZoomIn.setContentAreaFilled(false);
        jButtonZoomIn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonZoomInMouseClicked(evt);
            }
        });

        jButtonZoomOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/zoomout.png")));
        jButtonZoomOut.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("zoom_out"));
        jButtonZoomOut.setBorder(null);
        jButtonZoomOut.setContentAreaFilled(false);
        jButtonZoomOut.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonZoomOutMouseClicked(evt);
            }
        });

        jLabel1.setText(java.util.ResourceBundle.getBundle("lang").getString("zoom"));

        jLabelPorcent.setText("0 %");

        jButtonZoom100.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/zoom100.png")));
        jButtonZoom100.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("zoom_real"));
        jButtonZoom100.setBorder(null);
        jButtonZoom100.setContentAreaFilled(false);
        jButtonZoom100.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonZoom100MouseClicked(evt);
            }
        });

        jButtonZoomAjuste.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/zoomajuste.png")));
        jButtonZoomAjuste.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("zoom_window"));
        jButtonZoomAjuste.setBorder(null);
        jButtonZoomAjuste.setContentAreaFilled(false);
        jButtonZoomAjuste.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonZoomAjusteMouseClicked(evt);
            }
        });

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancelar.png")));
        jButtonCancelar.setText(java.util.ResourceBundle.getBundle("lang").getString("back"));
        jButtonCancelar.setToolTipText(java.util.ResourceBundle.getBundle("lang").getString("back_window"));
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonCancelarMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelImgPrincipalLayout = new org.jdesktop.layout.GroupLayout(jPanelImgPrincipal);
        jPanelImgPrincipal.setLayout(jPanelImgPrincipalLayout);
        jPanelImgPrincipalLayout.setHorizontalGroup(
            jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelImgPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanelImgPrincipalLayout.createSequentialGroup()
                        .add(jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel1)
                            .add(jButtonZoomIn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButtonZoomOut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButtonZoomAjuste, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButtonZoom100, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabelPorcent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE))
                    .add(jPanelImgPrincipalLayout.createSequentialGroup()
                        .add(jButtonCancelar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonGuardar)))
                .addContainerGap())
        );
        jPanelImgPrincipalLayout.setVerticalGroup(
            jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelImgPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelImgPrincipalLayout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanelImgPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButtonCancelar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jButtonGuardar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanelImgPrincipalLayout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabelPorcent)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonZoomIn)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonZoomOut)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonZoom100)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonZoomAjuste)))
                .addContainerGap())
        );

        jPanelImgPrincipalLayout.linkSize(new java.awt.Component[] {jButtonCancelar, jButtonGuardar}, org.jdesktop.layout.GroupLayout.VERTICAL);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelImgPrincipal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelImgPrincipal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        imagepanel.setImage(bi);
        jLabelPorcent.setText(""+imagepanel.zoomAjuste()+" %");
    }//GEN-LAST:event_formWindowOpened
    
    private void jButtonGuardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonGuardarMouseClicked
        int returnVal = filesave.showSaveDialog(this);
        if(returnVal == filesave.APPROVE_OPTION){
            this.setVisible(false);
            this.dispose();
        }
    }//GEN-LAST:event_jButtonGuardarMouseClicked
    
    private void jButtonCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarMouseClicked
        this.setVisible(false);
        this.dispose();
        System.gc ();
    }//GEN-LAST:event_jButtonCancelarMouseClicked
    
    private void jButtonZoomAjusteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonZoomAjusteMouseClicked
        this.jLabelPorcent.setText(imagepanel.zoomAjuste() + " %");
    }//GEN-LAST:event_jButtonZoomAjusteMouseClicked
    
    private void jButtonZoom100MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonZoom100MouseClicked
        this.jLabelPorcent.setText(imagepanel.zoom100() + " %");
    }//GEN-LAST:event_jButtonZoom100MouseClicked
    
    private void jButtonZoomOutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonZoomOutMouseClicked
        this.jLabelPorcent.setText(imagepanel.zoomOut() + " %");
    }//GEN-LAST:event_jButtonZoomOutMouseClicked
    
    private void jButtonZoomInMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonZoomInMouseClicked
        this.jLabelPorcent.setText(imagepanel.zoomIn() + " %");
    }//GEN-LAST:event_jButtonZoomInMouseClicked
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonZoom100;
    private javax.swing.JButton jButtonZoomAjuste;
    private javax.swing.JButton jButtonZoomIn;
    private javax.swing.JButton jButtonZoomOut;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelPorcent;
    private javax.swing.JPanel jPanelImgPrincipal;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    private ImagePanel imagepanel;
}
